package com.sc.admin.common.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;

/**
 *@Author shen chen
 *@Date 2024-03-27
 */
@Component
public class EnvironmentUtils {
    private static Environment environment;

    @Autowired
    public EnvironmentUtils(Environment environment) {
        EnvironmentUtils.environment = environment;
    }

    public static String getConfigValue(String key) {
        return environment.getProperty(key);
    }

    public static String getConfigValue(String key, String defaultValue) {
        String property = getConfigValue(key);

        return ObjectUtils.isEmpty(property) ? defaultValue : property;
    }
}
